from django import forms
from django.conf import settings

from .models import ServerApplication
from .libs import utils


class LoginForm(forms.Form):
    username = forms.CharField(label='用户名', max_length=256, initial='')
    password = forms.CharField(label='密码', max_length=100, widget=forms.PasswordInput(), initial='')
    remember = forms.BooleanField(label='下次自动登录', initial=True, required=False)


class ServerApplicationForm(forms.ModelForm):
    approver_info = utils.get_boss_approver_info()
    approver_choices = {}
    for email, info in approver_info.items():
        name = info.get('respectful_name')
        if not name:
            name = info.get('name')
        approver_choices[email] = name

    approver_choices = list(approver_choices.items())
    approver = forms.ChoiceField(label='审批人', required=True, choices=approver_choices)

    class Meta:
        model = ServerApplication
        exclude = ['pub_date']
